<?php


namespace App\Api\Models;


use Illuminate\Database\Eloquent\Model;

class CmcPromotionPintuanOrder extends Model
{
    protected $table = 'cmc_promotion_pintuan_orders';
    //生成订单


    //查询订单列表
    static public function getOrder($uid)
    {
        return CmcPromotionPintuanOrder::where('uid',$uid)->get()->toArray();
    }

    public static function getPintuanGoods()
    {
        return self::select('pintuan_id')->get()->toArray();
    }

    public static function getYearPintuanGoods($pintuan_id)
    {
        $time = date('Y-m-d',time()-86400);

        $data = CmcPromotionPintuan::where('pintuan_id',$pintuan_id)->get()->toArray();

        $count = count($data);

        for($i=0;$i<$count;$i++){
            $data[$i]['created_at'] = strtotime(str_replace('T',' ',$data[$i]['created_at']));
        }

        $all = [];

        for($j=0;$j<$count;$j++){
            if($data[$j]['created_at'] <$time && $data[$j]['created_at']<$time+86400){
                unset($data[$j]);
            }else{
                $all[$j] = [$data[$j]['goods_id'],$data[$j]['goods_name'],$data[$j]['created_at']];
            }
        }
        return $all;
    }

    static public function pintuanList($pintuan_id,$where)
    {
        $pintuanId = CmcPromotionPintuan::where('pintuan_id',$pintuan_id)->get([$where])->toArray();
        $arr = [];
        $count = count($pintuanId);
        for($i=0;$i<$count;$i++){
            $arr = Goods::where('goods_id',$pintuanId[$i]['goods_id'])
                        ->select('goods_id','goods_name','goods_image','created_at')
                        ->get()
                        ->toArray();
        }
        return $arr;
    }
}
